package com.example.wangyuyuan.androidframe.manager;

import com.example.wangyuyuan.androidframe.mvp.ChatFragment.fragment.ChatFragment;
import com.example.wangyuyuan.androidframe.mvp.FavouriteFragment.fragment.FavouriteFragment;
import com.example.wangyuyuan.androidframe.mvp.FriendFragment.fragment.FriendFragment;
import com.example.wangyuyuan.androidframe.mvp.MineFragment.fragment.MineFragment;

/**
 * Created by wangyuyuan on 2017/5/18.
 * 主页面fragment工厂，提供单利模式
 */

public class FragmentFactory {

    private static FragmentFactory mInstance;

    public FragmentFactory() {
    }

    public static FragmentFactory getInstance() {
        if (mInstance == null) {
            synchronized (FragmentFactory.class) {
                if (mInstance == null) {
                    mInstance = new FragmentFactory();
                }
            }
        }
        return mInstance;
    }

    private ChatFragment chatFragment;
    private FriendFragment friendFragment;
    private FavouriteFragment favouriteFragment;
    private MineFragment mineFragment;

    public ChatFragment getChatFragment() {
        if (chatFragment == null) {
            synchronized (FragmentFactory.class) {
                if (chatFragment == null) {
                    chatFragment = new ChatFragment();
                }
            }
        }
        return chatFragment;
    }

    public FriendFragment getFriendFragment() {
        if (friendFragment == null) {
            synchronized (FragmentFactory.class) {
                if (friendFragment == null) {
                    friendFragment = new FriendFragment();
                }
            }
        }
        return friendFragment;
    }

    public FavouriteFragment getFavouriteFragment() {
        if (favouriteFragment == null) {
            synchronized (FragmentFactory.class) {
                if (favouriteFragment == null) {
                    favouriteFragment = new FavouriteFragment();
                }
            }
        }
        return favouriteFragment;
    }

    public MineFragment getMineFragment() {
        if (mineFragment == null) {
            synchronized (FragmentFactory.class) {
                if (mineFragment == null) {
                    mineFragment = new MineFragment();
                }
            }
        }
        return mineFragment;
    }
}
